Use [MusicLine]
--Run this script in Query Analyzer to create the tables for MusicLine

Set NoCount On
If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AlbumsArtistsId]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
    Alter Table [dbo].[Albums] DROP CONSTRAINT AlbumsArtistsId
GO

If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CutsAlbumId]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
    Alter Table [dbo].[Cuts] DROP CONSTRAINT CutsAlbumId
GO

If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Cuts]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    Drop table [dbo].[Cuts]
If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Albums]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    Drop table [dbo].[Albums]
If exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Artists]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
    Drop table [dbo].[Artists]
GO

Create Table Artists
    (
    ArtistId Integer  Primary Key,
    Name Varchar(100) Not Null
    )
Go
Create Table Albums
    (
    AlbumId Integer Primary Key,
    ArtistId Integer Not Null Constraint AlbumsArtistsId Foreign Key References Artists(ArtistId),
    Title Varchar(255) Not Null,
    LengthInSeconds Integer Not Null Default(0) Constraint MinimumAlbumLength Check (LengthInSeconds >= 0)
    )
Go
Create Table Cuts
    (
    AlbumId Integer Constraint CutsAlbumId Foreign Key References Albums(AlbumId),
    CutNumber Integer Primary Key (AlbumId, CutNumber),
    Title Varchar(255) Not Null,
    LengthInSeconds Integer Not Null Default(0) Constraint MinimumCutLength Check (LengthInSeconds >= 0)
    )
Go

Insert Into Artists (ArtistId, Name) Values (1, 'Joe Satriani')
Insert Into Artists (ArtistId, Name) Values (2, 'Talking Heads')
Insert Into Artists (ArtistId, Name) Values (3, 'Aerosmith')
Insert Into Artists (ArtistId, Name) Values (4, 'Tom Petty')
Go

Insert Into Albums (AlbumId, ArtistId, Title, LengthInSeconds) Values (1, 1, 'Flying In A Blue Dream', 661)
Insert Into Albums (AlbumId, ArtistId, Title, LengthInSeconds) Values (2, 2, 'Stop Making Sense', 663)
Insert Into Albums (AlbumId, ArtistId, Title, LengthInSeconds) Values (3, 3, 'Pump', 279)
Insert Into Albums (AlbumId, ArtistId, Title, LengthInSeconds) Values (4, 1, 'Surfing With The Alien', 200)
Insert Into Albums (AlbumId, ArtistId, Title, LengthInSeconds) Values (5, 4, 'Full Moon Fever', 0)
Go

Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (2, 1, 'Psycho Killer', 408)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (3, 2, 'Janie''s Got A Gun', 279)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (1, 3, 'The Forgotten, Part II', 311)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (4, 4, 'Always With You, Always With Me', 200)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (2, 5, 'Take Me To The River', 255)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (1, 6, 'I Believe', 350)

Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (4, 7, 'Yer So Bad', 185)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (4, 8, 'Zombie Zoo', 176)
Insert Into Cuts (AlbumId, CutNumber, Title, LengthInSeconds) Values (4, 9, 'Free Fallin', 254)
Go

Print 'MusicLine has been created.'

